<%@ page import = "arrowandsphere.*" %>
<jsp:useBean id="bean" class="arrowandsphere.Bean" />

<html>
<body>
<%
    String requestPlayerName = request.getParameter("playerName");
    if (requestPlayerName != null) {
        session.setAttribute("playerName", requestPlayerName);
    }
    
    String playerName = (String)session.getAttribute("playerName");
    if (playerName == null) {
        out.println("<form action=\"arrow_and_sphere.jsp\" method=\"post\">O seu nome <input type=\"text\" name=\"playerName\" /><input type=\"submit\" value=\"Submeter\" /></form>");
    }
    else {
        out.println("<h1>Bem-vindo, " + playerName + "</h1>");
        out.println("<form action=\"arrow_and_sphere.jsp\" method=\"post\">Criar sessao para <input type=\"text\" name=\"numberOfPlayers\" /> jogadores. <input type=\"submit\" value=\"Criar sessao\" /></form>");
        
        String numberOfPlayers = request.getParameter("numberOfPlayers");
        if (numberOfPlayers != null) {
            bean.createSession(Integer.parseInt(numberOfPlayers));
        }
        for (int i = 0; i < bean.readSessions().size(); ++i) {
            out.println("Sessao " +i +"<form action=\"arrow_and_sphere_game.jsp\" method=\"post\"><input type=\"submit\" value=\"Juntar-me a esta sessao\" /></form>");
        }
    }
%>
</body>
</html>
